package com.ojoin.trade.common_core.web.service.impl;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ojoin.trade.common.exception.BusinessException;
import com.ojoin.trade.common.utils.LogUtils;
import com.ojoin.trade.common.web.dao.BaseDao;
import com.ojoin.trade.common.web.service.impl.BaseServiceImpl;
import com.ojoin.trade.common_core.web.dao.TbAdminUserDao;
import com.ojoin.trade.common_core.web.domain.TbAdminUser;
import com.ojoin.trade.common_core.web.service.AdminUserBaseService;

/**
 * 保理员服务实现
 * @author guoting
 *
 */
@Service
public class AdminUserBaseServiceImpl extends BaseServiceImpl<TbAdminUser> implements
		AdminUserBaseService {

	@Autowired
	private TbAdminUserDao dao;
	
	@Override
	protected BaseDao<TbAdminUser> getBaseDao() {
		return dao;
	}

	@Override
	public int insertAdminUser(TbAdminUser adminuservo) throws BusinessException {
		if (StringUtils.isEmpty(adminuservo.getLoginName()) || 
			StringUtils.isEmpty(adminuservo.getLoginPassword()))
			throw new BusinessException("管理员用户名或密码或权限数据为空，请检查.");
			
		TbAdminUser existuser = this.queryAdminUserByName(adminuservo.getLoginName());
		if (existuser != null)
			throw new BusinessException("管理员name->" + adminuservo.getLoginName() + "已存在，请修改后重试.");
		
		return super.insert(adminuservo);
	}
	
	@Override
	public TbAdminUser queryAdminUserByNameAndPwd(String name,
			String pwd) throws BusinessException {
		LogUtils.getT0loanLog().info("查询管理员详细信息：name->" + name + " pwd->" + pwd + ".");
		return ((TbAdminUserDao) this
				.getBaseDao()).queryAdminUserByNameAndPwd(name, pwd);
	}

	@Override
	public TbAdminUser queryAdminUserByName(String name) throws BusinessException {
		LogUtils.getT0loanLog().info("查询管理员详细信息：name->" + name +".");
		return ((TbAdminUserDao) this
				.getBaseDao()).queryAdminUserByName(name);
	}

}
